Begin;

CREATE SEQUENCE _100351.gsp_commercial_details_gsp_id_seq
    INCREMENT BY 1;

CREATE SEQUENCE _100351.gsp_item_details_item_id_seq
    INCREMENT BY 1;

Create Table _100351.gsp_commercial_details(
gsp_id integer DEFAULT
nextval('_100351.gsp_commercial_details_gsp_id_seq'::text) NOT
NULL,
buyer_id integer,
bcontact_id integer,
account_id integer,
office_contact_id integer,
factory_contact_id integer,
ship_mode_id integer,
ship_from_city integer,
ship_from_country integer,
ship_to_country integer,
ship_to_port integer,
ship_date date,
remarks character varying,
support_documents character varying,
origin_requirements character varying,
book_nos character varying
);

ALTER TABLE ONLY _100351.gsp_commercial_details
    ADD CONSTRAINT gsp_id_pk PRIMARY KEY (gsp_id);

ALTER TABLE ONLY _100351.gsp_commercial_details
    ADD COLUMN signatory character varying;

-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT buyer_id_fk FOREIGN KEY (buyer_id)
-- REFERENCES _jbuyer(buyer_jid) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;

-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT bcontact_id_fk FOREIGN KEY (bcontact_id)
-- REFERENCES company_contact(contact_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT office_contact_id_fk FOREIGN KEY (office_contact_id)
-- REFERENCES company_contact(contact_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT factory_contact_id_fk FOREIGN KEY (factory_contact_id)
-- REFERENCES company_contact(contact_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT account_id_fk FOREIGN KEY (account_id)
-- REFERENCES _jaccount(account_jid) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT ship_mode_id_fk FOREIGN KEY (ship_mode_id)
-- REFERENCES _mship_mode(shipment_mode_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT ship_from_city_fk FOREIGN KEY (ship_from_city)
-- REFERENCES _mcity(city_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT ship_to_country_fk FOREIGN KEY (ship_to_country)
-- REFERENCES _mcountry(country_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT ship_from_country_fk FOREIGN KEY (ship_from_country)
-- REFERENCES _mcountry(country_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;
-- 
-- ALTER TABLE ONLY _100351.gsp_commercial_details
--     ADD CONSTRAINT ship_to_port_fk FOREIGN KEY (ship_to_port)
-- REFERENCES _mport(port_id) ON UPDATE CASCADE
-- DEFERRABLE INITIALLY DEFERRED;

Create Table _100351.gsp_item_details(
item_id integer DEFAULT nextval('_100351.gsp_item_details_item_id_seq'::text)
NOT
NULL,
gsp_id integer,
item_no char(5),
marks_nos_packages character varying,
description character varying,
origin character varying,
gross_weight character varying,
nos_invoice_date character varying
);

ALTER TABLE ONLY _100351.gsp_item_details
    ADD CONSTRAINT item_id_pk PRIMARY KEY (item_id);


ALTER TABLE ONLY _100351.gsp_item_details
    ADD CONSTRAINT gsp_id_fk FOREIGN KEY (gsp_id)
REFERENCES gsp_commercial_details(gsp_id) ON UPDATE CASCADE
DEFERRABLE INITIALLY DEFERRED;
Commit;